/**
 * 
 */
package edu.pku.sei.modeler.uml.commands.statemachine;

import edu.pku.sei.modeler.model.core.MetaModelElement;
import edu.pku.sei.modeler.model.uml.BehaviorStateMachines.Pseudostate;
import edu.pku.sei.modeler.model.uml.BehaviorStateMachines.State;
import edu.pku.sei.modeler.model.uml.BehaviorStateMachines.StateMachine;
import edu.pku.sei.modeler.model.uml.BehaviorStateMachines.Transition;
import edu.pku.sei.modeler.uml.commands.ConnectionModelCreateCommand;

/**
 * @author YanYan
 * 
 */
public class CreateTransitionCommand extends ConnectionModelCreateCommand {
	
	public CreateTransitionCommand(MetaModelElement connectionModel,
			MetaModelElement sourceModel) {
		super(connectionModel, sourceModel);
	}
//	private Transition transition;

	public boolean canExecute() {
		return true;
	}
	
	public void execute() {
		Transition transition = (Transition) connectionModel;
		if(sourceModel != null){
			if(sourceModel instanceof State)
				((State)sourceModel).getOutgoing().add(transition);
			else if(sourceModel instanceof Pseudostate)
				((Pseudostate)sourceModel).getOutgoing().add(transition);
			else if (sourceModel instanceof StateMachine)
				((StateMachine)sourceModel).getOutgoing().add(transition);
		}
		if(targetModel != null){
			if(targetModel instanceof State)
				((State)targetModel).getIncoming().add(transition);
			else if(targetModel instanceof Pseudostate)
				((Pseudostate)targetModel).getIncoming().add(transition);
			else if (sourceModel instanceof StateMachine)
				((StateMachine)sourceModel).getIncoming().add(transition);
		}
		if(transition != null){
			transition.setContainer(sourceModel);
			transition.setModel(sourceModel.getModel());
		}
	}
	
	public void undo() {
		//TODO
	}

}
